<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" placeholder="enter the name you search" v-model="searchName" @keyup.enter="doSearch"/>
      <button @click="doSearch">Search</button>
    </div>
  </section>
</template>

<script>
  import PubSub from 'pubsub-js'

  export default {
    name: "Search",
    data() {
      return {
        searchName: ''
      }
    },
    methods: {
      doSearch() {
        // 校验数据
        const searchName = this.searchName.trim();
        if (searchName) {
          // 发布消息
          PubSub.publish('searchRepo', searchName);
          // 清空输入框
          this.searchName = '';
        }

      }
    }
  }
</script>

<style scoped>

</style>
